import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

// import admin from "./modules/admin"
// import user from "./modules/user"


/*自动化失败...先手动吧,等我再更新
 const mod = {}
const file = require.context('./modules', false, /\.js$/i)
file.keys().forEach(item => {
  let val = file(item).default
  console.log(val);
}); */
const modulesFn = require.context('./modules', false, /\.js$/i)
const modules = modulesFn.keys().reduce((prev, curr) => {
  let value = {...modulesFn(curr).default, namespaced: true}
  let key = curr.match(/\.\/(\w+)\.js/i)[1]
  prev[key] = value
  return prev
}, {})

Vue.use(Vuex)

export default new Vuex.Store({
  // ...admin,
  // ...user,
  modules,
  ...getters
})
